extends CanvasLayer


@onready var score_label: Label = get_node("Label/Score")
@onready var gameOver_label: Label = get_node("GameOver")

@export var current_score: int = 0

func _ready():
    MessageCenter.subscribe(self, "game_over", on_game_over)
    MessageCenter.subscribe(self, "score_changed", on_score_changed)

func _process(_delta: float):
     if Input.is_key_pressed(KEY_ESCAPE):
        get_tree().quit()


func on_score_changed(_sender: Object, score: int):
    current_score += score
    score_label.text = str(current_score)


func on_game_over(_sender: Object, is_game_over: bool):
    if is_game_over:
        gameOver_label.visible = true
    else:
        gameOver_label.visible = false